public class Main {
    private double a;
    private double b;
    private double c;

    // 构造方法
    public Main(double a, double b, double c) {
        if (a == 0) {
            throw new IllegalArgumentException("a不能为零，必须是一个二次方程");
        }
        this.a = a;
        this.b = b;
        this.c = c;
    }

    // 计算判别式
    private double calculateDiscriminant() {
        return b * b - 4 * a * c;
    }

    // 求解方程
    public void solve() {
        double discriminant = calculateDiscriminant();
        if (discriminant > 0) {
            double root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
            double root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
            System.out.println("方程有两个不同的实根：");
            System.out.println("根1: " + root1);
            System.out.println("根2: " + root2);
        } else if (discriminant == 0) {
            double root = -b / (2 * a);
            System.out.println("方程有一个重根：");
            System.out.println("根: " + root);
        } else {
            System.out.println("方程没有实根。");
        }
    }

    public static void main(String[] args) {
        Main equation = new Main(1, -3, 2); // 示例: x^2 - 3x + 2
        equation.solve();
    }
}